home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsbittab.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.9 KB  |  137 lines

  1. /* Copyright (C) 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsbittab.c,v 1.2 2000/09/19 19:00:25 lpd Exp $ */
  20. /* Tables for bit operations */
  21. #include "stdpre.h"
  22. #include "gsbittab.h"
  23.  
  24. /* ---------------- Byte processing tables ---------------- */
  25.  
  26. /*
  27.  * byte_reverse_bits[B] = the byte B with the order of bits reversed.
  28.  */
  29. const byte byte_reverse_bits[256] = {
  30.     bit_table_8(0, 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80)
  31. };
  32.  
  33. /*
  34.  * byte_right_mask[N] = a byte with N trailing 1s, 0 <= N <= 8.
  35.  */
  36. const byte byte_right_mask[9] = {
  37.     0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xff
  38. };
  39.  
  40. /*
  41.  * byte_count_bits[B] = the number of 1-bits in a byte with value B.
  42.  */
  43. const byte byte_count_bits[256] __attribute__ ((aligned (4))) = {
  44.     bit_table_8(0, 1, 1, 1, 1, 1, 1, 1, 1)
  45. };
  46.  
  47. /* ---------------- Scanning tables ---------------- */
  48.  
  49. /*
  50.  * byte_bit_run_length_N[B], for 0 <= N <= 7, gives the length of the
  51.  * run of 1-bits starting at bit N in a byte with value B,
  52.  * numbering the bits in the byte as 01234567.  If the run includes
  53.  * the low-order bit (i.e., might be continued into a following byte),
  54.  * the run length is increased by 8.
  55.  */
  56.  
  57. #define t8(n) n,n,n,n,n+1,n+1,n+2,n+11
  58. #define r8(n) n,n,n,n,n,n,n,n
  59. #define r16(n) r8(n),r8(n)
  60. #define r32(n) r16(n),r16(n)
  61. #define r64(n) r32(n),r32(n)
  62. #define r128(n) r64(n),r64(n)
  63. const byte byte_bit_run_length_0[256] __attribute__ ((aligned (4))) = {
  64.     r128(0), r64(1), r32(2), r16(3), r8(4), t8(5)
  65. };
  66. const byte byte_bit_run_length_1[256] __attribute__ ((aligned (4))) = {
  67.     r64(0), r32(1), r16(2), r8(3), t8(4),
  68.     r64(0), r32(1), r16(2), r8(3), t8(4)
  69. };
  70. const byte byte_bit_run_length_2[256] __attribute__ ((aligned (4))) = {
  71.     r32(0), r16(1), r8(2), t8(3),
  72.     r32(0), r16(1), r8(2), t8(3),
  73.     r32(0), r16(1), r8(2), t8(3),
  74.     r32(0), r16(1), r8(2), t8(3)
  75. };
  76. const byte byte_bit_run_length_3[256] __attribute__ ((aligned (4))) = {
  77.     r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
  78.     r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
  79.     r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
  80.     r16(0), r8(1), t8(2), r16(0), r8(1), t8(2)
  81. };
  82. const byte byte_bit_run_length_4[256] __attribute__ ((aligned (4))) = {
  83.     r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
  84.     r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
  85.     r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
  86.     r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
  87. };
  88.  
  89. #define rr8(a,b,c,d,e,f,g,h)\
  90.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
  91.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
  92.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
  93.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
  94.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
  95.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
  96.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
  97.   a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h
  98. const byte byte_bit_run_length_5[256] __attribute__ ((aligned (4))) = {
  99.     rr8(0, 0, 0, 0, 1, 1, 2, 11)
  100. };
  101. const byte byte_bit_run_length_6[256] __attribute__ ((aligned (4))) = {
  102.     rr8(0, 0, 1, 10, 0, 0, 1, 10)
  103. };
  104. const byte byte_bit_run_length_7[256] __attribute__ ((aligned (4))) = {
  105.     rr8(0, 9, 0, 9, 0, 9, 0, 9)
  106. };
  107.  
  108. /* Pointer tables indexed by bit number. */
  109.  
  110. const byte *const byte_bit_run_length[8] = {
  111.     byte_bit_run_length_0, byte_bit_run_length_1,
  112.     byte_bit_run_length_2, byte_bit_run_length_3,
  113.     byte_bit_run_length_4, byte_bit_run_length_5,
  114.     byte_bit_run_length_6, byte_bit_run_length_7
  115. };
  116. const byte *const byte_bit_run_length_neg[8] = {
  117.     byte_bit_run_length_0, byte_bit_run_length_7,
  118.     byte_bit_run_length_6, byte_bit_run_length_5,
  119.     byte_bit_run_length_4, byte_bit_run_length_3,
  120.     byte_bit_run_length_2, byte_bit_run_length_1
  121. };
  122.  
  123. /*
  124.  * byte_acegbdfh_to_abcdefgh[acegbdfh] = abcdefgh, where the letters
  125.  * denote the individual bits of the byte.
  126.  */
  127. const byte byte_acegbdfh_to_abcdefgh[256] = {
  128.     bit_table_8(0, 0x80, 0x20, 0x08, 0x02, 0x40, 0x10, 0x04, 0x01)
  129. };
  130.  
  131. /* Some C compilers insist on having executable code in every file.... */
  132. void gsbittab_dummy(P0());    /* for picky compilers */
  133. void
  134. gsbittab_dummy(void)
  135. {
  136. }
  137.